package com.weixing.mall.base.enums;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * 自定义Jackson枚举序列化
 * @author  Small
 * @since v1.0
 */
public class BaseEnumSerializer extends StdSerializer<IBaseEnum> {


    public BaseEnumSerializer() {

        super(IBaseEnum.class);

    }


    public BaseEnumSerializer(Class t) {

        super(t);

    }


    @Override
    public void serialize(IBaseEnum baseEnum, JsonGenerator generator, SerializerProvider provider) throws IOException {

        generator.writeStartObject();

        generator.writeFieldName("value");

        generator.writeObject(baseEnum.getValue());

        generator.writeFieldName("desp");

        generator.writeString(baseEnum.getDesp());

        generator.writeEndObject();

    }


}